package bus;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

public class Month {
	private Year year;
	private String name;
	private Integer intVal;
	private GregorianCalendar calendar;
	
	private List<Day> days;
	
	public Month(Year year, Integer intVal) {
		this.year = year;
		// TODO:  Set the name from the input
		this.intVal = intVal;
		this.calendar = new GregorianCalendar(year.getYear(), intVal, 1);
		
		populateDays(this.calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
	}
	
	private void populateDays(Integer daysInMonth) {	
		days = new ArrayList<Day>();
		for (int i = 0; i < daysInMonth; i++) {
			Integer j = i + 1;
			GregorianCalendar calendar = new GregorianCalendar(year.getYear(), intVal, j);
			Integer intDay = calendar.get(Calendar.DAY_OF_WEEK);
			addDay(new Day(this, intDay));
		}
	}
	
	private void addDay(Day day) {
		this.days.add(day);
	}
	
	public List<Day> getDays() {
		return this.days;
	}
}
